package com.lingshi.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingshi.shopping_common.entity.Brand;
import com.lingshi.shopping_common.result.BaseResult;
import com.lingshi.shopping_common.service.IBrandService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jinken
 * @since 2024-06-24
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @DubboReference
    private IBrandService brandService;

    @GetMapping("/findById")
    public BaseResult findById(Long id){
        Brand brand = brandService.findById(id);
        return BaseResult.success(brand);
    }

    @PostMapping("/add")
    public BaseResult add(@RequestBody Brand brand){
        brandService.add(brand);
        return BaseResult.success();
    }

    @PutMapping("/update")
    public BaseResult update(@RequestBody Brand brand){
        brandService.update(brand);
        return BaseResult.success();
    }

    @DeleteMapping("/delete")
    public BaseResult delete(Long id){
        brandService.delete(id);
        return BaseResult.success();
    }

    @GetMapping("/search")
    public BaseResult search(Brand brand,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer size){
        Page<Brand> search = brandService.search(brand, page, size);
        return BaseResult.success(search);
    }

    @GetMapping("/all")
    public BaseResult findAll(){
        List<Brand> brands = brandService.findAll();
        return BaseResult.success(brands);
    }

}
